from django.shortcuts import render,redirect
from .models import Teachingscore
from django.urls import reverse
# Create your views here.

def index(request):
    data=Teachingscore.objects.all()
    return render(request,'teaching_time.html',{'data':data})
def add(request):
    if request.method=='POST':
        name=request.POST.get('teaching_name')
        start_time=request.POST.get('start_time')
        end_time=request.POST.get('end_time')
        Teachingscore.objects.create(teaching_name=name,start_time=start_time,end_time=end_time)
        return redirect(reverse('score:teachingscore_list'))
    return render(request,'teaching_add.html')
def delsco(request,id):
    dele=Teachingscore.objects.get(id=id)
    dele.delete()
    return redirect(reverse('score:teachingscore_list'))

def updatesco(request,u_id):
    if request.method=='POST':
        id=request.POST.get('id')
        name=request.POST.get('teaching_name')
        start_time=request.POST.get('start_time')
        end_time=request.POST.get('end_time')
        Teachingscore.objects.filter(id=id).update(teaching_name=name,start_time=start_time,end_time=end_time)
        return redirect(reverse('score:teachingscore_list'))
    data = Teachingscore.objects.get(id=u_id)
    return render(request, 'teaching_updat.html',{'data':data})

